import { defineStore } from 'pinia'

/**
 * 
 * @methods setUserInfos 
 */
export const useUserInfo = defineStore('userInfo', {
  state: (): any => ({
    userInfos: uni.getStorageSync('userInfo') || {
      email: '',
      id: '',
    },
    token: uni.getStorageSync('token'),
    deferredPrompt: null,
    isPwa: false, 
  }),
  actions: {
    async setUserInfos(userInfos: any) {
      
      uni.setStorageSync('userInfo', userInfos)
      this.userInfos = userInfos
      console.log(this.userInfos)
    },
    async setToken(token: string) {
      
      uni.setStorageSync('token', token)
      this.token = token
    },
    async reset() {
      uni.removeStorageSync('userInfo')
      uni.removeStorageSync('token')
      this.userInfos = {
        email: '',
        id: '',
      }
      this.token = ''
    },
    async setDeferredPrompt(deferredPrompt: any) {
      this.deferredPrompt = deferredPrompt
    },
    async setIsPwa(isPwa: boolean) {
      this.isPwa = isPwa
    },
  },
})
